﻿using VideoStore.Domain.Entities;
using VideoStore.Services.Dto;
using VideoStore.Services.Translation.Base;

namespace VideoStore.Services.Translation
{
    public class CatalogueTranslator : BaseTranslator
    {
        #region Overrides of BaseTranslator

        /// <summary>
        /// Translates to concrete entity.
        /// </summary>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="dto">The dto.</param>
        /// <param name="concreteEntity">The concrete entity.</param>
        /// <returns></returns>
        public override TEntity TranslateToConcreteEntity<TDto, TEntity>(TDto dto, TEntity concreteEntity)
        {
            CatalogueDto tempDto = dto as CatalogueDto;
            if (tempDto != null)
            {
                Catalogue tempEntity = concreteEntity as Catalogue;
                if (tempEntity != null)
                {
                    tempEntity.id = tempDto.Id;
                    tempEntity.catalogue_no = tempDto.CatNo;
                    tempEntity.director = tempDto.Director;
                    tempEntity.genre = tempDto.Genre;
                    tempEntity.price = tempDto.Price;
                    tempEntity.title = tempDto.Title;
                    return tempEntity as TEntity;
                }
            }
            return default(TEntity);
        }

        /// <summary>
        /// Translates to concrete dto.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="concreteDto">The concrete dto.</param>
        /// <returns></returns>
        public override TDto TranslateToConcreteDto<TEntity, TDto>(TEntity entity, TDto concreteDto)
        {
            Catalogue tempEntity = entity as Catalogue;
            if (tempEntity != null)
            {
                CatalogueDto tempDto = concreteDto as CatalogueDto;
                if (tempDto != null)
                {
                    tempDto.Id = tempEntity.id;
                    tempDto.CatNo = tempEntity.catalogue_no;
                    tempDto.Director = tempEntity.director;
                    tempDto.Genre = tempEntity.genre;
                    tempDto.Price = (float) tempEntity.price;
                    tempDto.Title = tempEntity.title;
                    return tempDto as TDto;
                }
            }
            return default(TDto);
        }

        #endregion
    }
}